#!/bin/sh
parameter="costCoef";
#params=("0.1" "0.05" "0.01" "0.005" "0.001" "0.0005" "0.0001");
#params=("0.2" "0.4" "0.6" "0.8" "0.85" "0.88" "0.9" "0.95" "0.99");
#params=("0.1" "0.5" "0.9" "1" "5" "10" "15" "20" "25" "30");
#params=("1" "3" "5" "7" "9" "13" "15" "17" "20");
params=("1" "5" "10" "30" "50" "70" "100" "150" "200" "250" "300" "400" "500" "600" "700" "800" "900" "1000")

files=`ls *.$parameter`
echo "param hodnota;chyba;stavy" > "$parameter.csv"
for i in $files; do
    IFS=$'\n'
    counter=0
    for j in `cat $i` ; do

        if [ "${lineValuesSum[$counter]}" = "" ];
        then
          lineValuesSum[$counter]=0
          statesSum[$counter]=0
        fi
        deviation=`echo $j | cut -d" " -f3 | tr ',' '.'`
        states=`echo $j | cut -d" " -f4`
        lineValuesSum[$counter]=`echo "scale=4;${lineValuesSum[$counter]} + $deviation" | bc`
        statesSum[$counter]=`echo "scale=4;${statesSum[$counter]} + $states" | bc`
        counter=`expr $counter + 1`
    done
    IFS=$' '
done
counter=0
for i in ${lineValuesSum[@]} ; do
    lineValuesSum[$counter]=`echo "scale=4;${lineValuesSum[$counter]} / 200" | bc`
    statesSum[$counter]=`echo "scale=4;${statesSum[$counter]} / 200" | bc`
    echo "${params[$counter]};${lineValuesSum[$counter]};${statesSum[$counter]}" | tr '.' ',' >> "$parameter.csv"
    counter=`expr $counter + 1`

done
